package com.dlut.java3;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @Author: LiuHeng
 * @Description:
 * @Date: 2022-09-18 8:38
 */
public class T0918_JingWei {

    static int numA = 0;
    static int numS = 0;
    static int numD = 0;
    static int numF = 0;
    static HashMap<Character, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = s.length();
        map.put('A', -n / 4);
        map.put('S', -n / 4);
        map.put('D', -n / 4);
        map.put('F', -n / 4);
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            map.put(c, map.get(c) + 1);
        }
        int left = 0, right = 0;
        int minLen = n;
        while (left <= right && right < n){

            if (!judge()){
                char c = s.charAt(right);
                map.put(c, map.get(c) - 1);
                right++;
            }else {
                minLen = Math.min(minLen, right - left);
                char c = s.charAt(left);
                map.put(c, map.get(c) + 1);
                left ++;
            }
        }
        map.clear();
        System.out.println(minLen);
    }

    private static boolean judge() {
        if (map.get('A') <= 0 && map.get('S') <= 0 && map.get('D') <= 0 && map.get('F') <= 0){
            return true;
        }
        return false;
    }

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = s.length();
        int temp = 1;
        int max = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) != s.charAt(i-1)){
                temp++;
            }else {
                max = Math.max(max, temp);
                temp = 1;
            }
        }
        max = Math.max(max, temp);
        if (max >= 3)
            System.out.println(max);
        else
            System.out.println(0);
    }



    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        int[] num = new int[m];
        for (int i = 0; i < m; i++) {
            num[i] = in.nextInt();
        }
        int[] arr = new int[m+1];
        arr[0] = 0;
        for (int i = 1; i < m + 1; i++) {
            arr[i] = arr[i-1] + num[i-1];
        }
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        int target = in.nextInt();
        int[][] num = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                num[i][j] = in.nextInt();
            }
        }
        if (dfs(num,0,0,m-1,n-1, target))
            System.out.println("TRUE");
        else
            System.out.println("FALSE");
    }

    private static boolean dfs(int[][] num, int i1, int i2, int i3, int i4, int target) {
        if (i1 > i3 || i2 > i4)
            return false;
        if (num[i1][i2] == target || num[i3][i4] == target)
            return true;
        if (i1 < i3 && (dfs(num, i1+1, i2, i3, i4, target) ||
                dfs(num, i1, i2, i3-1, i4, target)))
            return true;
        if (i2 < i4 && (dfs(num, i1, i2+1, i3, i4, target) ||
                dfs(num, i1, i2, i3, i4-1, target)))
            return true;
        return false;
    }
}
